package sketch.seg.cd.exp;

import java.util.Vector;

public class CDRhoStat {

	private Vector<Data> stat;

	public static class Data {

		private int K;

		private double[] rho;

		public int getK() {
			return K;
		}

		public void setK(int k) {
			K = k;
		}

		public double[] getRho() {
			return rho;
		}

		public void setRho(double[] rho) {
			this.rho = rho;
		}

		public Data(int k) {
			setK(k);
		}

		public Data(int k, double[] rhos) {
			setK(k);
			setRho(rhos);
		}
	}

	public CDRhoStat() {
		stat = new Vector<Data>();
	}

	public void addData(Data data) {
		stat.add(data);
	}

	public Data getDataByK(int K) {
		for (Data d : getStat()) {
			if (d.getK() == K)
				return d;
		}
		return null;
	}

	public Vector<Data> getStat() {
		return stat;
	}

	public void setStat(Vector<Data> stat) {
		this.stat = stat;
	}

	public double getMaxRhoByK(int K) {
		Data data = getDataByK(K);
		if (data == null)
			return 0;

		double max = 0;
		for (int i = 0; i < data.getRho().length; i++) {
			if (max < data.getRho()[i])
				max = data.getRho()[i];
		}
		return max;
	}

	public double getMinRhoByK(int K) {
		Data data = getDataByK(K);
		if (data == null)
			return 0;

		double min = Double.MAX_VALUE;
		for (int i = 0; i < data.getRho().length; i++) {
			if (min > data.getRho()[i])
				min = data.getRho()[i];
		}
		return min;
	}
}
